package com.csu.exception;

import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.exception.NotPermissionException;
import cn.dev33.satoken.exception.NotRoleException;
import cn.dev33.satoken.util.SaResult;
import com.csu.common.CommonResponse;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    // 处理未登录异常
    @ExceptionHandler(NotLoginException.class)
    public CommonResponse<Object> handleNotLoginException(NotLoginException e) {
        return CommonResponse.createForError("未登录，请先登录");
    }

    // 处理没有角色异常
    @ExceptionHandler(NotRoleException.class)
    public CommonResponse<Object> handleNotRoleException(NotRoleException e) {
        return CommonResponse.createForError("角色访问权限不足");
    }

    // 处理没有权限异常
    @ExceptionHandler(NotPermissionException.class)
    public CommonResponse<Object> handleNotPermissionException(NotPermissionException e) {
        return CommonResponse.createForError("角色访问权限不足");
    }

//    // 处理其他异常
//    @ExceptionHandler(Exception.class)
//    public CommonResponse<Object> handleException(Exception e) {
//        return CommonResponse.createForError("服务器内部错误");
//    }
}
